#include <stdio.h>
void swap(char *a, char *b)
{
     char t=*a;
   *a=*b;
   *b=t;
}
void printnext(char *a);
int main(void)
{
   char a[50];
   while(1)
   {
        scanf("%s",a);
        if(strcmp(a,"#")==0)
           return 0;
        printnext(a);
   }
   return 0;
}
void printnext(char *a)
{
       int i,j,k,n;
   n=strlen(a);
   j=n-2;
   while(a[j]>=a[j+1] && j>=0) j= j-1;
   if(j<0)
   {    printf("No Successor\n");
      return;
   }
   k=n-1;
   while(a[j] >= a[k]) k=k-1;
   swap(&a[j], &a[k]);
   i=n-1; k=j+1;
   while(i>=k)
   {   swap(&a[i],&a[k]);
      i--;k++;
   }
   printf("%s\n",a);
} 
